;

var account_set_ops = {
    init: function () {
        this.eventBind();
    },
    eventBind: function () {
        $(".wrap_account_set .save").click(function () {
            var btn_target = $(this); //当前点击的对象
            //防止用户多次点击     
            if (btn_target.hasClass("disabled")) {
                common_ops.alert("正在处理！！请不要重复提交");
                return;
            }
            //获取标签    
            var nickname_target = $(".wrap_account_set input[name=nickname]");
            // 获取值
            var nickname = nickname_target.val();
            var mobile_target = $(".wrap_account_set input[name=mobile]");
            // 获取值
            var mobile = mobile_target.val();
            var email_target = $(".wrap_account_set input[name=email]");
            // 获取值
            var email = email_target.val();
            var login_name_target = $(".wrap_account_set input[name=login_name]");
            // 获取值
            var login_name = login_name_target.val();
            var login_pwd_target = $(".wrap_account_set input[name=login_pwd]");
            // 获取值
            var login_pwd = login_pwd_target.val();


            if (nickname.lenth < 1) {
                common_ops.tip("请输入符合规范的姓名~", nickname_target);
                return false;
            }

            if (mobile.lenth < 1) {
                common_ops.tip("请输入符合规范的手机号码~", mobile_target);
                return false;
            }

            if (email.lenth < 1) {
                common_ops.tip("请输入符合规范的邮箱~", email_target);
                return false;
            }

            if (login_name.lenth < 1) {
                common_ops.tip("请输入符合规范的用户名~", login_name_target);
                return false;
            }

            if (login_pwd.lenth < 6) {
                common_ops.tip("请输入符合规范的登录密码~", login_pwd_target);
                return false;
            }


            //禁止再次点击
            btn_target.addClass("disabled");

            var data = {
                nickname: nickname,
                mobile: mobile,
                email: email,
                login_name: login_name,
                login_pwd: login_pwd,
                id:$(".wrap_account_set input[name=id]").val()
            };

            $.ajax({
                url: common_ops.buildUrl("/account/set"),
                type: 'POST',
                data: data,
                dataType: 'json',
                success: function (res) {
                    btn_target.removeClass("disabled");
                    var callback = null;
                    if (res.code == 200) {
                        //回调函数
                        callback = function () {
                            window.location.href = common_ops.buildUrl("/account/index");
                        }
                    }
                    //此为封装函数 传递服务器返回的信息 并传递一个回调函数
                    common_ops.alert(res.msg, callback);
                }
            });

        });
    }
};


//页面加载完成之后调用初始化方法
$(document).ready(function () {
    account_set_ops.init();
});












